<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="kaiji">
    <meta name="keyword" content="权限, 博客, 信息, 列表">
    <title>权限信息列表</title>
	<#include "admin/common.ftl" />
	
	<style type="text/css">
		#delBtn {margin-left: 5px;}
	</style>
  </head>

  <body>

  <section id="container" class="">
      <!--header start-->
      <#include "admin/header.ftl" />
      <!--header end-->
      <!--sidebar start-->
      <#include "admin/sidebar.ftl" />
      <!--sidebar end-->
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
              <!-- page start-->
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">权限信息列表</header>
                          <!-- 自定义工具栏 -->
                          <div class="panel-body">
                              <form id="searchForm" class="form-inline" role="form">
                                <@privUrlTag code="B00114">
								<button id="delBtn" type="button" class="btn btn-danger pull-right btn-sm">
								  <i class="icon-trash">删除</i>
								</button>
                            		</@privUrlTag>                              
                                <@privUrlTag code="B00112">
                            		<button id="addBtn" type="button" class="btn btn-success pull-right btn-sm">
                            		  <i class="icon-plus">添加</i>
                            		</button>
                            		</@privUrlTag>                              
                            	  </form>
                          </div>
                          <!-- 结束自定义工具栏 -->
                       </section>
                       <section class="panel">
                          <table class="table table-striped border-top" id="dataTable">
                          <thead>
                          <tr>
                              <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#dataTable .checkboxes" /></th>
                              <th class="dt-body-center">序号</th>
                              <th class="dt-body-center">编码</th>
                              <th class="dt-body-center">权限名称</th>
                              <th class="dt-body-center">上级权限名称</th>
                              <th class="dt-body-center">创建时间</th>
                              <th class="dt-body-center">操作</th>
                          </tr>
                          </thead>
                          
                          </table>
                      </section>
                  </div>
              </div>
              <!-- page end-->
	      </section>
      </section>
      <!--main content end-->
  </section>

<#include "admin/common_js.ftl" />
<script src="${ctx}/js/jquery.validate.min.js" ></script>
<script type="text/javascript" src="${ctx}/assets/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="${ctx}/assets/data-tables/DT_bootstrap.js"></script>
<script src="${ctx}/js/dynamic-table.js"></script>
<script src="${ctx}/js/moment.js"></script>
<script type="text/javascript">
$(function() {
	var $dataTable = $("#dataTable").DataTable({
    	ajax: {   
            url: "${ctx}/admin/jur/list.html"
        },
        columns: [
            {"data": "jurisdictionId"},
            {"data": null},
            {"data": "code"},
            {"data": "name"},
            {
        		"data": "parentId",
        		"render": function(data, type, full, meta) {
        			 return  0 ==  data ? "无" : full.parentEntity.name;
        		}
        	},
            {
        		"data": "createDate",
        		"render": function(data, type, full, meta) {
        			 return  moment(data).format("YYYY-MM-DD HH:mm:ss");
        		}
            
            },
            {"data": null}
        ],
        "columnDefs": [
        	{
		        "targets": 0,
		        "className": 'dt-body-center',
		        "render": function (data, type, full, meta){
		            return '<input type="checkbox" name="ids" value="' + $('<div/>').text(data).html() + '">';
		        }
	        },
         	{
             "targets": -1,
             "defaultContent": "<@privUrlTag code="B00113"><button class='btn btn-primary btn-xs editBtn'><i class='icon-edit'>编辑</i></button></@privUrlTag>"
         	}
	    ],
        fnDrawCallback: function(){
            var api = this.api();
        　　 var startIndex= api.context[0]._iDisplayStart;
        　　 api.column(1).nodes().each(function(cell, i) {
        　　　　    cell.innerHTML = startIndex + i + 1;
        　　 });
        		$(this).find('input[type=checkbox]').removeAttr('checked');  
        }
	      	
    });
	    
		
	// 删除
	$("#delBtn").click(function () {
	    	var $chks = $("input[name='ids']:checked");
	    	var $ids = [];
	    	$chks.each(function(){
	    		$ids.push($(this).val());
	    	});
	    	if ($ids.length <= 0) {
	    		layer.alert("请至少选择一项!", {icon: 0});
	    		return false;
	    	}
			
	    	$.ajax({
			url: "${ctx}/admin/jur/delete.html",
			data: {ids: $ids},
		    type: "post",
		    dataType: "json",
		    success: function(data) {
			    	if (data.success == 0) {
						layer.alert(data.message, {icon: 0});
			    	} else {
			    		layer.msg("删除成功!");
			    		$dataTable.draw();
			    	}
		    }
		});
	});
	
	// 添加
	$("#addBtn").click(function(){
		location.href = "${ctx}/admin/jur/add.html";
		return false;
	});
	
	 // 进入编辑
    $("#dataTable tbody").on("click", ".editBtn", function () {
		var data = $dataTable.row($(this).parents("tr")).data();
		location.href = "${ctx}/admin/jur/edit.html?id="+data.jurisdictionId;
		return false;
	});


});
</script>
  </body>
</html>